package com.huike.web.controller.report;

import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.domain.vo.LineChartVo;
import com.huike.report.domain.vo.VulnerabilityMapVo;
import com.huike.report.result.*;
import com.huike.report.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @Description 统计分析相关接口
 * @Date 2023-10-10
 */
@RestController
@Slf4j
@RequestMapping("/report")
@Api(tags = "统计分析相关接口")
public class ReportController extends BaseController {
    @Autowired
    private ReportService reportService;

    /**
     * 客户统计新增客户数报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("客户统计新增客户数报表")
    public LineChartVo contractStatistics(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        LineChartVo vo = reportService.contractStatistics(beginCreateTime,endCreateTime);
        return vo;
    }

    /**
     * 客户统计学科分布统计报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("客户统计学科分布统计报表")
    public AjaxResult<List<ReportSubjectStatisticsData>> subjectStatistics(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        return AjaxResult.success(reportService.subjectStatistics(beginCreateTime,endCreateTime));
    }

    /**
     * 客户统计明细列表
     * @param contract
     * @return
     */
    @GetMapping("/contractStatisticsList")
    @ApiOperation("客户统计明细列表")
    public TableDataInfo<List<TbContract>> contractStatisticsList(TbContract contract){
        startPage();
        List<TbContract> list = reportService.contractStatisticsList(contract);
        return getDataTable(list);
    }



    /**
     * 销售统计报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计报表")
    public LineChartVo salesStatistics(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        return reportService.salesStatistics(beginCreateTime,endCreateTime);
    }

    /**
     * 销售统计归属渠道明细列表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属渠道明细列表")
    public TableDataInfo<List<ReportSalesChannelStatisticsListData>> channelStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
        List<Map<String,Object>> list = reportService.channelStatisticsList(beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }

    /**
     * 销售统计归属部门明细列表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属部门明细列表")
    public TableDataInfo<List<ReportSalesDeptStatisticsListData>> deptStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
        List<Map<String,Object>> list = reportService.deptStatisticsList(beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }

    /**
     * 销售统计归属人报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属人报表")
    public TableDataInfo<List<ReportSalesOwnerShipStatisticsListData>> ownerShipStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
        List<Map<String,Object>> list = reportService.ownerShipStatisticsList(beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }


    /**
     * 线索统计新增线索数量报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/cluesStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("线索统计新增线索数量报表")
    public LineChartVo cluesStatistics(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        return reportService.cluesStatistics(beginCreateTime,endCreateTime);
    }

    /**
     * 线索统计线索转换率报表
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("线索统计线索转换率报表")
    public AjaxResult<VulnerabilityMapVo> getVulnerabilityMap(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        VulnerabilityMapVo vo = reportService.getVulnerabilityMap(beginCreateTime,endCreateTime);
        return AjaxResult.success(vo);
    }

    /**
     * 线索统计明细列表
     * @param tbClue
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    @ApiOperation("线索统计明细列表")
    public TableDataInfo<List<TbClue>> cluesStatisticsList(TbClue tbClue){
        startPage();
        List<TbClue> list = reportService.cluesStatisticsList(tbClue);
        return getDataTable(list);
    }



    /**
     * 渠道统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("渠道统计")
    public AjaxResult<List<ReportChannelStatisticsData>> chanelStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        return AjaxResult.success(reportService.chanelStatistics(beginCreateTime,endCreateTime));
    }

    /**
     * 渠道统计-活动统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("渠道统计-活动统计")
    public AjaxResult<List<ReportActivityStatisticsData>> activityStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        return AjaxResult.success(reportService.activityStatistics(beginCreateTime,endCreateTime));
    }

    /**
     * 渠道统计活动明细列表
     * @param activity
     * @return
     */
    @GetMapping("/activityStatisticsList")
    @ApiOperation("渠道统计活动明细列表")
    public TableDataInfo<List<ActivityStatisticsVo>> activityStatisticsList(TbActivity activity){
        List<ActivityStatisticsVo> list = reportService.activityStatisticsList(activity);
        return getDataTablePage(list);
    }
}
